package com.ibeeking.found.content.api.feign.fallback;

import com.ibeeking.found.content.api.feign.FileBClient;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class FileBFallbackFactory implements FallbackFactory<FileBClient> {
    @Override
    public FileBClient create(Throwable throwable) {
        return new FileBClient() {

            @Override
            public ResponseResult<String> uploadFile(MultipartFile file) throws IOException {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，文件上传失败。" + throwable.getMessage());
            }
        };
    }
}
